package com.itheima.hmshopping.dubbo.apiImpl;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.hmshopping.dubbo.api.SmsCouponProductRelationApi;
import com.itheima.hmshopping.dubbo.mapper.SmsCouponProductRelationMapper;
import com.itheima.hmshopping.entity.SmsCouponProductRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class SmsCouponProductRelationApiImpi implements SmsCouponProductRelationApi {
    @Autowired
    private SmsCouponProductRelationMapper smsCouponProductRelationMapper;
    //优惠券和产品的关系表
    @Override
    public void insertLists(List<SmsCouponProductRelation> productRelationList) {
        for (SmsCouponProductRelation smsCouponProductRelation : productRelationList) {
            smsCouponProductRelationMapper.insert(smsCouponProductRelation);
        }
    }

    //通过id删除
    @Override
    public void delete(Integer id) {
        Long aLong = Convert.toLong(id);
        LambdaQueryWrapper<SmsCouponProductRelation> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(SmsCouponProductRelation::getCouponId,aLong);
        smsCouponProductRelationMapper.delete(lambdaQueryWrapper);
    }

    //cid查询
    @Override
    public List<SmsCouponProductRelation> selectById(Integer id) {
        Long aLong = Convert.toLong(id);
        LambdaQueryWrapper<SmsCouponProductRelation> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(SmsCouponProductRelation::getCouponId,aLong);
        List<SmsCouponProductRelation> smsCouponProductRelations = smsCouponProductRelationMapper.selectList(lambdaQueryWrapper);
        return smsCouponProductRelations;
    }
}
